<?php
 $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_paulamarie");
 if(isSet($_REQUEST["uusleht"])){
 $kask=$yhendus->prepare("INSERT INTO mikrobussivedu (kliendisoov, kliendinimi) VALUES (?, ?)");
 $kask->bind_param("ss", $_REQUEST["kliendisoov"], $_REQUEST["kliendinimi"]);
 $kask->execute();
 header("Location: $_SERVER[PHP_SELF]");
 $yhendus->close();
 exit();
 }
 if(isSet($_REQUEST["kustutusid"])){
 $kask=$yhendus->prepare("DELETE FROM mikrobussivedu WHERE id=?");
 $kask->bind_param("i", $_REQUEST["kustutusid"]);
 $kask->execute(); 
 
 }
 
 if(!empty($_REQUEST["korras_id"])){
$kask=$yhendus->prepare(
"UPDATE mikrobussivedu SET pakkuminekinnitatud=1 WHERE id=?");
$kask->bind_param("i", $_REQUEST["korras_id"]);
$kask->execute();
}
?>
<!doctype html>

<html>
 <head>
 <title>Teated lehel</title>
 <style type="text/css">
 #menyykiht{
 float: left;
 padding-right: 30px;
 }
 #kliendinimikiht{
 float:left;
 }
 #jalusekiht{
 clear: left;
 }
 </style>
 </head>
 <body>
 <div id="menyykiht">
 <h2>Teated</h2>
 <ul>
 <?php
 $kask=$yhendus->prepare("SELECT id, kliendisoov FROM mikrobussivedu"); $kask->bind_result($id, $kliendisoov);
 $kask->execute();
 while($kask->fetch()){
 echo "<li><a href='?id=$id'>".
 htmlspecialchars($kliendisoov)."</a></li>";
 }
 ?>
 </ul>
 
 </div>
 <div id="kliendinimikiht">
 <?php
 if(isSet($_REQUEST["id"])){
 $kask=$yhendus->prepare("SELECT id, kliendisoov, kliendinimi FROM mikrobussivedu
 WHERE id=?");
 $kask->bind_param("i", $_REQUEST["id"]); 
 $kask->bind_result($id, $kliendisoov, $kliendinimi);
 $kask->execute();
 if($kask->fetch()){
 echo "<h2>".htmlspecialchars($kliendisoov)."</h2>";
 echo htmlspecialchars($kliendinimi);
 echo "<br /><a href='?kustutusid=$id'>kustuta</a>";
 echo "<br /><a href='?korras_id=$id'>kinnita</a>";
 } else {
 echo "Vigased andmed.";
 }
 ?>
 <?php
 }
 ?>
 </div>
 <div id="jalusekiht">
 </div>
 </body>
</html>
<?php
 $yhendus->close();
?>
